#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <string>
#include <string_view>
using ll = int64_t;
#define sl static inline
const ll maxn=255+5;
ll q;
std::string s,t,tmp;
bool dp[maxn][maxn];

sl std::string js(std::string_view s,std::string_view m){
    std::string n;
    for(char c:s){
        for(char cm:m){
            if(c==cm){
                n+=c;
                break;
            }
        }
    }
    return n;
}

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // std::cout<<js("aabcd","abd")<<", "<<js("caabd","abd")<<"\n";
    std::cin>>s>>t;
    for(char i='a';i<='r';i++){
        for(char j='a';j<='r';j++){
            dp[i][j] = js(s,std::string()+i+j)==js(t,std::string()+i+j);
            // std::cout<<js(s,std::string()+i+j)<<", "<<js(t,std::string()+i+j)<<"\n";
            // printf("dp[%c][%c]=%d\n",i,j,dp[i][j]);
        }
    }
    std::cin>>q;
    while(q--){
        std::cin>>tmp;
        bool res = true;
        res&=dp[tmp[0]][tmp[0]];
        for(ll i=0;i<tmp.size();i++){
            for(ll j=i+1;j<tmp.size();j++){
                res&=dp[tmp[i]][tmp[j]];
            }
        }
        std::cout<<(res?'Y':'N');
    }
    std::cout<<'\n';
}